#!/bin/bash
#
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
#

SH_TAP=1

if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
	UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
else
	UTILSSH="$(dirname "$0")/../utils/utils.sh"
fi

# shellcheck source=../utils/utils.sh
source "$UTILSSH"

NUM_TESTS=3

plan_tests $NUM_TESTS

tmp_metadata=$(mktemp)

# Test a valid trace directory.
"${BT_TESTS_BT2_BIN}" -o ctf-metadata "${BT_CTF_TRACES_PATH}/succeed/wk-heartbeat-u" > "$tmp_metadata"
ok $? "Run babeltrace -o ctf-metadata with a valid trace directory, correct exit status"

cmp -s "$tmp_metadata" "${BT_TESTS_DATADIR}/cli/test_output_ctf_metadata.ref"
ok $? "Run babeltrace -o ctf-metadata with a valid trace directory, correct output"

# Test an invalid trace directory.
"${BT_TESTS_BT2_BIN}" -o ctf-metadata "${BT_CTF_TRACES_PATH}" >/dev/null 2>&1
isnt $? 0 "Run babeltrace -o ctf-metadata with an invalid trace directory, expecting failure"

rm -f "$tmp_metadata"
